#define _CRT_SECURE_NO_WARNINGS 1
  struct ListNode {
 	int val;
 	struct ListNode *next;
 	ListNode(int x) : val(x), next(nullptr) {}
  };
 
class Solution {
public:
    ListNode* deleteDuplicates(ListNode* head)
    {
        if (head == nullptr) return nullptr;
        ListNode* prev = head;
        ListNode* cur = prev->next;
        while (cur)
        {
            if (cur->val == prev->val)
            {
                prev->next = cur->next;
                delete cur;
            }
            else
            {
                prev = prev->next;
            }
            cur = prev->next;
        }
        return head;
    }
};